/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * KiesWordList.java
 *
 * Created on 30-mei-2011, 13:52:40
 */

package view;

import connections.Query;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.List;
import main.ApplicatieMain;

/**
 *
 * @author Jeroen
 */
public class KiesWordList extends javax.swing.JFrame {

    private boolean multiplayer = false;
    private ApplicatieMain applicatieMain;
    private Query query;
    /** Creates new form KiesWordList */
    public KiesWordList(boolean multiplayer) {
        applicatieMain = ApplicatieMain.getInstance();
        query = applicatieMain.getQuery();

        this.multiplayer = multiplayer;

        initComponents();
        

        if(multiplayer){
            btnCancel.setEnabled(false);
            btnSpeel.setText("Verder!");
        }

        // Hoe groot is het scherm?
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (dim.width - this.getSize().width) /2;
        int y = (dim.height - this.getSize().height) /2;
        this.setLocation(x, y);
        this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
        this.setTitle("Woordenlijsten");
        updateWoordenlijst();
    }

    private void updateWoordenlijst(){
        List<String> wordLists = query.getWordLists(applicatieMain.getSelectedKlasID());
        cboxWoordenlijst.removeAllItems();
        for (String wordlist : wordLists){
            cboxWoordenlijst.addItem(wordlist);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblKiesWoordenlijst = new javax.swing.JLabel();
        cboxWoordenlijst = new javax.swing.JComboBox();
        btnSpeel = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblKiesWoordenlijst.setText("Kies een woordenlijst om te spelen:");

        cboxWoordenlijst.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        btnSpeel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        btnSpeel.setForeground(new java.awt.Color(0, 102, 0));
        btnSpeel.setText("Spelen!");
        btnSpeel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSpeel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSpeelActionPerformed(evt);
            }
        });

        btnCancel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        btnCancel.setForeground(new java.awt.Color(255, 0, 0));
        btnCancel.setText("Cancel");
        btnCancel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnSpeel, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))
                    .addComponent(cboxWoordenlijst, javax.swing.GroupLayout.Alignment.TRAILING, 0, 381, Short.MAX_VALUE)
                    .addComponent(lblKiesWoordenlijst, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblKiesWoordenlijst, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cboxWoordenlijst, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSpeel)
                    .addComponent(btnCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSpeelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSpeelActionPerformed

        applicatieMain.setSelectedWoordenlijst(
                query.getWordListID(applicatieMain.getSelectedKlasID(), // KlasID
                (String)cboxWoordenlijst.getSelectedItem())); // WoordenlijstNaam
        if(multiplayer){
            applicatieMain.getLobby().updateWordListLabel((String)cboxWoordenlijst.getSelectedItem());
            applicatieMain.getLobby().startLobby();
        } else {
            applicatieMain.showPage(new view.SingleSpelPagina());
        }
        this.dispose();
    }//GEN-LAST:event_btnSpeelActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnSpeel;
    private javax.swing.JComboBox cboxWoordenlijst;
    private javax.swing.JLabel lblKiesWoordenlijst;
    // End of variables declaration//GEN-END:variables

}
